<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/login.css}"/>
    <style type="text/css">
    </style>
</head>
<body>
<div class="login-top">
    <p class="cursor">
        <span>智能门禁系统管理平台</span>
        <em>修改密码</em>
    </p>
</div>
<nav class="login-pass mt30px">
    <div class="text-center red f16px">用户初次登陆，需修改初始密码，以提高账户安全性！</div>
    <ul>
        <li>
            <label><em class="red">*&nbsp;</em>新密码：</label>
            <div class="relative current">
                <span><input id="pwd" maxlength="18" type="text" placeholder="请输入密码"></span>
                <em><img th:src="@{/static/img/login_blank.png}"></em>
            </div>
        </li>
        <!--        <h6 class="red">验证码错误</h6>-->
        <li>
            <label><em class="red">*&nbsp;</em>确认密码：</label>
            <div class="relative">
                <span><input id="pwd2" maxlength="18" type="text" placeholder="请再次输入密码"></span>
                <em><img th:src="@{/static/img/login_blank.png}"></em>
                <!-- <em><img src="img/login_blank.png"></em> -->
            </div>
        </li>
        <li style="margin-top: 0;">
            <div class="gray f14px">密码至少6位，且为大小写字母、数字和字符中至少两类的组合</div>
        </li>
        <li>
            <label></label>
            <div class="btn-con text-center cursor">
                <span onclick="returnLoginPage()">取&nbsp;&nbsp;消</span>
                <span onclick="updatePwd()">提&nbsp;&nbsp;交</span>
            </div>
        </li>
    </ul>
</nav>
<script src="js/jquery-3.1.1.min.js" th:src="@{/static/js/jquery-3.1.1.min.js}" charset="utf-8"></script>
<script src="layui/layui.js" th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script src="js/leftSidebar.js" th:src="@{/static/js/leftSidebar.js}" charset="utf-8"></script>
<script th:inline="javascript">

    var basePath = [[${#request.getContextPath()}]];

    function updatePwd() {
        layui.use(['element', 'table', 'layer'], function () {

            var layer = layui.layer;
            var pwdRegex = new RegExp('(?=.*[^a-zA-Z0-9]).{6,18}');
            var pwd = $("#pwd").val();
            var pwd2 = $("#pwd2").val();

            if (isNull(pwd)) {
                layer.msg("请输入密码")
                return;
            }

            if (isNull(pwd2)) {
                layer.msg("请输入确认密码")
                return;
            }

            if (!(pwd == pwd2)) {
                layer.msg("密码不一致")
                return;
            }

            /* if (!pwdRegex.test(pwd) || !pwdRegex.test(pwd2)) {
                 layer.msg("您的密码复杂度太低（密码中必须包含大小写字母、数字、特殊字符）")
                 return;
             }*/
            var data = {pwd: pwd};
            $.ajax({
                url: basePath + "/user/updatePwd",
                type: "post",
                async: false,
                data: data,
                dataType: "json",
                success: function (data) {
                    if (data.code == 200) {
                        layer.alert(data.msg, function () {
                            window.top.location.href = basePath + "/index";
                        })
                    } else {

                    }
                }
            })

        })
    }

    function returnLoginPage() {
        window.location.href = basePath + "/login";
    }

    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }
</script>
</body>
</html>
